using System;
using UnityEngine;

namespace CinemaDirector
{
	[Serializable]
	public class Position
	{
		public enum PositionType
		{
			WorldValue = 0,
			LocalValue = 1,
			TransformValue = 2,
			Current = 3
		}

		public PositionType positionType;

		public Vector3 position;

		public Transform transform;

		[NonSerialized]
		public Vector3 currentPosition;

		public void SetWorldPosition(Vector3 worldPosition)
		{
			positionType = PositionType.WorldValue;
			position = worldPosition;
		}

		public void SetLocalPosition(Vector3 localPosition)
		{
			positionType = PositionType.LocalValue;
			position = localPosition;
		}

		protected Vector3 LocalToWorld(Transform trans, Vector3 val)
		{
			return trans.parent.TransformPoint(val);
		}

		public Vector3 GetWorldPosition(Transform transform)
		{
			if (positionType == PositionType.Current)
			{
				return currentPosition;
			}
			if (positionType == PositionType.WorldValue)
			{
				return position;
			}
			if (positionType == PositionType.LocalValue)
			{
				return LocalToWorld(transform, position);
			}
			if (positionType == PositionType.TransformValue)
			{
				return this.transform.position;
			}
			return position;
		}
	}
}
